package com.zzptc.zzsgz.bdsjws.activities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.adapter.BBXAdapter;
import com.zzptc.zzsgz.bdsjws.db.BBXDao;
import com.zzptc.zzsgz.bdsjws.listener.OnRecyclerItemClickListener;
import com.zzptc.zzsgz.bdsjws.utils.DividerGridItemDecoration;
import com.zzptc.zzsgz.bdsjws.vo.BBX;

import java.util.List;

import butterknife.BindView;

public class BBXActivity extends BaseActivity {
@BindView(R.id.rv_bbx)
    RecyclerView rv_Bbx;
    List<BBX> list;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_bbx;
    }

    @Override
    public void initData() {
        //要到数据库中去数据出来
      BBXDao bbxDao= MyApplication.getDaoSession().getBBXDao();
        list= bbxDao.loadAll();
       //final List<BBX> list= bbxDao.loadAll();
        //用RecyclerView显示数据
        BBXAdapter bbxAdapter=new BBXAdapter(list);
        RecyclerView.LayoutManager layoutManager=new GridLayoutManager(this,4);
        rv_Bbx.setAdapter(bbxAdapter);
        rv_Bbx.setLayoutManager(layoutManager);
        rv_Bbx.addItemDecoration(new DividerGridItemDecoration(this));
        rv_Bbx.addOnItemTouchListener(new OnRecyclerItemClickListener(rv_Bbx){
            @Override
            public void onItemClick(RecyclerView.ViewHolder vh) {
                super.onItemClick(vh);
                BBX bbx=list.get(vh.getPosition());
              if (bbx.getName().equals("家人守护")){
                  startActivities(new Intent[]{new Intent(BBXActivity.this, FamilyProtectActivity.class)});
              }else {
                  if (bbx.getName().equals("")){

                  }
              }
               // Toast.makeText(BBXActivity.this, "", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLongClick(RecyclerView.ViewHolder vh) {
                super.onLongClick(vh);
            }
        });
    }

    @Override
    public void initView() {

    }
}
